﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:documentFlowMapping_outSubmit
	/// </summary>
	public partial class documentFlowMapping_outSubmit
	{
		public documentFlowMapping_outSubmit()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("documentFlowMapping_id", "documentFlowMapping_outSubmit"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int documentFlowMapping_id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from documentFlowMapping_outSubmit");
			strSql.Append(" where documentFlowMapping_id=@documentFlowMapping_id");
			SqlParameter[] parameters = {
					new SqlParameter("@documentFlowMapping_id", SqlDbType.Int,4)
			};
			parameters[0].Value = documentFlowMapping_id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(Maticsoft.Model.documentFlowMapping_outSubmit model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into documentFlowMapping_outSubmit(");
			strSql.Append("documentFlowMapping_name,documentFlowMapping_creatTime,documentFlowMapping_creatUser,document_tableName,flow_id,flow_order,flow_name,isLastFlow,flow_op,pmid,depid)");
			strSql.Append(" values (");
			strSql.Append("@documentFlowMapping_name,@documentFlowMapping_creatTime,@documentFlowMapping_creatUser,@document_tableName,@flow_id,@flow_order,@flow_name,@isLastFlow,@flow_op,@pmid,@depid)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@documentFlowMapping_name", SqlDbType.VarChar,50),
					new SqlParameter("@documentFlowMapping_creatTime", SqlDbType.DateTime),
					new SqlParameter("@documentFlowMapping_creatUser", SqlDbType.Int,4),
					new SqlParameter("@document_tableName", SqlDbType.VarChar,50),
					new SqlParameter("@flow_id", SqlDbType.Int,4),
					new SqlParameter("@flow_order", SqlDbType.Int,4),
					new SqlParameter("@flow_name", SqlDbType.VarChar,100),
					new SqlParameter("@isLastFlow", SqlDbType.Bit,1),
					new SqlParameter("@flow_op", SqlDbType.VarChar,50),
					new SqlParameter("@pmid", SqlDbType.Int,4),
					new SqlParameter("@depid", SqlDbType.Int,4)};
			parameters[0].Value = model.documentFlowMapping_name;
			parameters[1].Value = model.documentFlowMapping_creatTime;
			parameters[2].Value = model.documentFlowMapping_creatUser;
			parameters[3].Value = model.document_tableName;
			parameters[4].Value = model.flow_id;
			parameters[5].Value = model.flow_order;
			parameters[6].Value = model.flow_name;
			parameters[7].Value = model.isLastFlow;
			parameters[8].Value = model.flow_op;
			parameters[9].Value = model.pmid;
			parameters[10].Value = model.depid;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.documentFlowMapping_outSubmit model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update documentFlowMapping_outSubmit set ");
			strSql.Append("documentFlowMapping_name=@documentFlowMapping_name,");
			strSql.Append("documentFlowMapping_creatTime=@documentFlowMapping_creatTime,");
			strSql.Append("documentFlowMapping_creatUser=@documentFlowMapping_creatUser,");
			strSql.Append("document_tableName=@document_tableName,");
			strSql.Append("flow_id=@flow_id,");
			strSql.Append("flow_order=@flow_order,");
			strSql.Append("flow_name=@flow_name,");
			strSql.Append("isLastFlow=@isLastFlow,");
			strSql.Append("flow_op=@flow_op,");
			strSql.Append("pmid=@pmid,");
			strSql.Append("depid=@depid");
			strSql.Append(" where documentFlowMapping_id=@documentFlowMapping_id");
			SqlParameter[] parameters = {
					new SqlParameter("@documentFlowMapping_name", SqlDbType.VarChar,50),
					new SqlParameter("@documentFlowMapping_creatTime", SqlDbType.DateTime),
					new SqlParameter("@documentFlowMapping_creatUser", SqlDbType.Int,4),
					new SqlParameter("@document_tableName", SqlDbType.VarChar,50),
					new SqlParameter("@flow_id", SqlDbType.Int,4),
					new SqlParameter("@flow_order", SqlDbType.Int,4),
					new SqlParameter("@flow_name", SqlDbType.VarChar,100),
					new SqlParameter("@isLastFlow", SqlDbType.Bit,1),
					new SqlParameter("@flow_op", SqlDbType.VarChar,50),
					new SqlParameter("@pmid", SqlDbType.Int,4),
					new SqlParameter("@depid", SqlDbType.Int,4),
					new SqlParameter("@documentFlowMapping_id", SqlDbType.Int,4)};
			parameters[0].Value = model.documentFlowMapping_name;
			parameters[1].Value = model.documentFlowMapping_creatTime;
			parameters[2].Value = model.documentFlowMapping_creatUser;
			parameters[3].Value = model.document_tableName;
			parameters[4].Value = model.flow_id;
			parameters[5].Value = model.flow_order;
			parameters[6].Value = model.flow_name;
			parameters[7].Value = model.isLastFlow;
			parameters[8].Value = model.flow_op;
			parameters[9].Value = model.pmid;
			parameters[10].Value = model.depid;
			parameters[11].Value = model.documentFlowMapping_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int documentFlowMapping_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from documentFlowMapping_outSubmit ");
			strSql.Append(" where documentFlowMapping_id=@documentFlowMapping_id");
			SqlParameter[] parameters = {
					new SqlParameter("@documentFlowMapping_id", SqlDbType.Int,4)
			};
			parameters[0].Value = documentFlowMapping_id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string documentFlowMapping_idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from documentFlowMapping_outSubmit ");
			strSql.Append(" where documentFlowMapping_id in ("+documentFlowMapping_idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.documentFlowMapping_outSubmit GetModel(int documentFlowMapping_id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 documentFlowMapping_id,documentFlowMapping_name,documentFlowMapping_creatTime,documentFlowMapping_creatUser,document_tableName,flow_id,flow_order,flow_name,isLastFlow,flow_op,pmid,depid from documentFlowMapping_outSubmit ");
			strSql.Append(" where documentFlowMapping_id=@documentFlowMapping_id");
			SqlParameter[] parameters = {
					new SqlParameter("@documentFlowMapping_id", SqlDbType.Int,4)
			};
			parameters[0].Value = documentFlowMapping_id;

			Maticsoft.Model.documentFlowMapping_outSubmit model=new Maticsoft.Model.documentFlowMapping_outSubmit();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.documentFlowMapping_outSubmit DataRowToModel(DataRow row)
		{
			Maticsoft.Model.documentFlowMapping_outSubmit model=new Maticsoft.Model.documentFlowMapping_outSubmit();
			if (row != null)
			{
				if(row["documentFlowMapping_id"]!=null && row["documentFlowMapping_id"].ToString()!="")
				{
					model.documentFlowMapping_id=int.Parse(row["documentFlowMapping_id"].ToString());
				}
				if(row["documentFlowMapping_name"]!=null)
				{
					model.documentFlowMapping_name=row["documentFlowMapping_name"].ToString();
				}
				if(row["documentFlowMapping_creatTime"]!=null && row["documentFlowMapping_creatTime"].ToString()!="")
				{
					model.documentFlowMapping_creatTime=DateTime.Parse(row["documentFlowMapping_creatTime"].ToString());
				}
				if(row["documentFlowMapping_creatUser"]!=null && row["documentFlowMapping_creatUser"].ToString()!="")
				{
					model.documentFlowMapping_creatUser=int.Parse(row["documentFlowMapping_creatUser"].ToString());
				}
				if(row["document_tableName"]!=null)
				{
					model.document_tableName=row["document_tableName"].ToString();
				}
				if(row["flow_id"]!=null && row["flow_id"].ToString()!="")
				{
					model.flow_id=int.Parse(row["flow_id"].ToString());
				}
				if(row["flow_order"]!=null && row["flow_order"].ToString()!="")
				{
					model.flow_order=int.Parse(row["flow_order"].ToString());
				}
				if(row["flow_name"]!=null)
				{
					model.flow_name=row["flow_name"].ToString();
				}
				if(row["isLastFlow"]!=null && row["isLastFlow"].ToString()!="")
				{
					if((row["isLastFlow"].ToString()=="1")||(row["isLastFlow"].ToString().ToLower()=="true"))
					{
						model.isLastFlow=true;
					}
					else
					{
						model.isLastFlow=false;
					}
				}
				if(row["flow_op"]!=null)
				{
					model.flow_op=row["flow_op"].ToString();
				}
				if(row["pmid"]!=null && row["pmid"].ToString()!="")
				{
					model.pmid=int.Parse(row["pmid"].ToString());
				}
				if(row["depid"]!=null && row["depid"].ToString()!="")
				{
					model.depid=int.Parse(row["depid"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select documentFlowMapping_id,documentFlowMapping_name,documentFlowMapping_creatTime,documentFlowMapping_creatUser,document_tableName,flow_id,flow_order,flow_name,isLastFlow,flow_op,pmid,depid ");
			strSql.Append(" FROM documentFlowMapping_outSubmit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" documentFlowMapping_id,documentFlowMapping_name,documentFlowMapping_creatTime,documentFlowMapping_creatUser,document_tableName,flow_id,flow_order,flow_name,isLastFlow,flow_op,pmid,depid ");
			strSql.Append(" FROM documentFlowMapping_outSubmit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM documentFlowMapping_outSubmit ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.documentFlowMapping_id desc");
			}
			strSql.Append(")AS Row, T.*  from documentFlowMapping_outSubmit T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "documentFlowMapping_outSubmit";
			parameters[1].Value = "documentFlowMapping_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetDistinctList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct documentFlowMapping_name ");
            strSql.Append(" FROM documentFlowMapping_outSubmit ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion  ExtensionMethod
    }
}

